﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

using Wicresoft.Common;
using MonthlyDB.Entity;
using Monthly.Framework.BusinessLogic;

public partial class Page_EditDept : BaseAuthenticationPage
{



    public Guid MonthlyID
    {
        get
        {
            if (!string.IsNullOrEmpty(Request.QueryString["ID"]))
                return new Guid(Request.QueryString["ID"]);
            return Guid.Empty;
        }
    }

    public string SearchClause
    {
        get
        {
            if (ViewState["SearchClause"] == null)
                ViewState["SearchClause"] = "1=1";
            return ViewState["SearchClause"].ToString();
        }
        set
        {
            ViewState["SearchClause"] = value;
        }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        this.Title = "部门添加";

        if (!IsPostBack)
        {

            if (MonthlyID != Guid.Empty)
            {
                this.Title = "部门编辑";
                MonthlyDB.Entity.Depts monthly = new MonthlyDB.Entity.Depts(MonthlyID);
                monthly.Load();

                tbSymbol.Text = monthly.DeptName;

            }
        }
    }

    protected void lbtnSave_Click(object sender, EventArgs e)
    {
        string script = string.Empty;
        MonthlyDB.Entity.Depts monthly = new MonthlyDB.Entity.Depts(MonthlyID);
        if (monthly.Load("DeptName='" + tbSymbol.Text.Replace("'", "''") + "'") && MonthlyID == Guid.Empty)
        {

            script = "<script>alert('已存在" + tbSymbol.Text + "!'); </script>";
        }
        else
        {
            monthly = new Depts();
            monthly.ID = MonthlyID;

            if (!monthly.Load())
            {
                monthly = new Depts();
                monthly.ID = Guid.NewGuid();
                monthly.DeptName = tbSymbol.Text.Trim();
                monthly.CreateTime = DateTime.Now;
                monthly.Add();
            }
            else
            {
                monthly.DeptName = tbSymbol.Text.Trim();
                monthly.Save();
            }
            
            script = "<script>alert('保存成功!');refreshParent();window.close();</script>";
        }
        ClientScript.RegisterStartupScript(this.GetType(), "Close", script);

    }


}
